package com.ling.core.view.builder;

import com.bstek.dorado.view.widget.Control;
import com.bstek.dorado.view.widget.base.SplitPanel;
import com.ling.core.view.ViewComponent;
import org.springframework.stereotype.Component;

/**
 * @author bo.wang
 * @since 2013-2-21
 */
@Component
public class SplitPanelBuilder extends AbstractControlBuilder {

    public void build(Object control, ViewComponent parentViewComponent) {
        SplitPanel sp = (SplitPanel) control;
        String id = sp.getId();
        ViewComponent component = this.generateViewComponent(id, SplitPanel.class);
        parentViewComponent.addChildren(component);
        buildChild(component, sp.getMainControl());
        buildChild(component, sp.getSideControl());
    }

    private void buildChild(ViewComponent component, Control control) {
        if (control == null) return;
        for (IControlBuilder builder : this.builders) {
            if (builder.support(control)) {
                builder.build(control, component);
                break;
            }
        }
    }

    public boolean support(Object control) {
        return control instanceof SplitPanel;
    }

}
